#include "CSerialPort.h"
#include "Tracker.h"
#include "getAmmo_cv.h"
#include "global.h"
#include "DataStruct.h"
using namespace std;
using namespace cv;

static char mode = 3; //模式切换，0为辅助打击，1为大神符

vector<Point2f> center;
DataStruct send_data = {0, 0, 0, 0, 0x5A};
const int IMG_WIDTH = 640, IMG_HEIGHT =480;

int main(int argc, char **argv)
{
	VideoCapture video_in("/home/ubuntu/5734.avi");
	string video_name = "123";

	Ptr<AKAZE> akaze = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT);
	akaze->setThreshold(akaze_thresh);
	Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-Hamming");
	Tracker akaze_tracker(akaze, matcher);
	namedWindow(video_name);
	center.push_back(Point2f(IMG_WIDTH / 2, IMG_HEIGHT / 2));
 	akaze_tracker.setFirstFrame(mode);

	Mat akaze_res;
	Mat frame;
	double Time;
	char tmp_mode=mode;

	while(1)
	{
		Time = (double)cvGetTickCount();
		video_in >> frame;
		
		if (frame.empty())
			{
				cout << "\n\n       empty     \n" << endl;
				return 0;
			}
			
		detectArmor(frame,send_data,akaze_tracker,mode,tmp_mode);
		Time = (double)cvGetTickCount() - Time;
        Time = Time / (cvGetTickFrequency() * 1000);
        cout << "Time:" << Time << endl;
		imshow(video_name,frame);
	}
	
	return 0;
}
